// SpinButton.cpp: implementation of the SpinButton class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SpinButton.h"
#include "SpinButtonPeer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(SpinButton, AWTComponent)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SpinButton::SpinButton()
{
	construct(VERTICAL);
}

SpinButton::SpinButton(int orientation)
{
	construct(orientation);
}

SpinButton::~SpinButton()
{

}

CWnd* SpinButton::createComponent()					 
{
	CWnd* wParent = getParent()->getPeer();
	if (wParent == NULL)
		return wParent;
	CSpinButtonCtrl* pwnd = new SpinButtonPeer(this);
	DWORD dwStyle = WS_CHILD | WS_VISIBLE;
	if (m_orientation == HORIZONTAL)
		dwStyle |= UDS_HORZ;
	pwnd->Create(dwStyle, getBounds(), wParent, 0);
	if (!m_enabled)
		pwnd->EnableWindow(FALSE);
	return pwnd;
}

CSize SpinButton::getMinimumSize()
{
	return getPreferredSize();
}

CSize SpinButton::getPreferredSize()
{
	if (m_peer == NULL)
		return CSize(0,0);
	CSize sz;
	if (m_orientation == HORIZONTAL)
	{
		sz.cx = ::GetSystemMetrics(SM_CXHSCROLL) * 2;
		sz.cy = ::GetSystemMetrics(SM_CXHSCROLL);
	}
	else
	{
		sz.cy = ::GetSystemMetrics(SM_CYVSCROLL) * 2;
		sz.cx = ::GetSystemMetrics(SM_CYVSCROLL);
	}
	
	return sz;
}

void SpinButton::processAdjustmentEvent(AWTAdjustmentEvent* e) 
{
  if (m_adjustmentListener != NULL) 
	{
    m_adjustmentListener->adjustmentValueChanged(e);
  }
}
